//
//  JiaochengxiangqingVC.m
//  AStage_shougongke
//
//  Created by 赵磊 on 16/1/19.
//  Copyright © 2016年 dllo. All rights reserved.
//
#import "aStageHeader.pch"
@interface JiaochengxiangqingVC ()
@property (nonatomic, retain) UIScrollView *scrollView;
@property (nonatomic, retain) NSArray *stepArr;
@end

@implementation JiaochengxiangqingVC
//- (void)dealloc
//{
//    [_scrollView release];
//    [_stepArr release];
//    [_hand_id release];
//    [super dealloc];
//}
// 页面即将出现 将tabBar显示
- (void)viewWillAppear:(BOOL)animated
{
    // tabBar显示
    self.tabBarController.tabBar.hidden = YES;
}
// 页面即将消失 将tabBar隐藏
- (void)viewWillDisappear:(BOOL)animated
{
    // tabBar隐藏
    self.tabBarController.tabBar.hidden = NO;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBarHidden = YES;
    self.scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
    _scrollView.pagingEnabled = YES;
    _scrollView.userInteractionEnabled = YES;
    // 隐藏scrollView的滑动条
    _scrollView.showsHorizontalScrollIndicator = NO;
    [self.view addSubview:_scrollView];
    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, HEIGHT - 50, WIDTH, 50)];
    view.backgroundColor = [UIColor whiteColor];
        [self.view addSubview:view];
    // 创建返回的button
    UIButton * fanhui = [UIButton buttonWithType:UIButtonTypeCustom];
    [fanhui setImage:[UIImage imageNamed:@"fanhui@2x"] forState:UIControlStateNormal];
    fanhui.frame = CGRectMake(0, 0, 50, 50);
    [fanhui addTarget:self action:@selector(fanhui) forControlEvents:UIControlEventTouchUpInside];
        [view addSubview:fanhui];
    [self dataHandler];
    [_scrollView release];
    [view release];
    [fanhui release];
}
// 创建scrollView
- (void)createScrollView
{
    _scrollView.contentSize = CGSizeMake(WIDTH * self.step, 0);
    for (NSInteger i = 0; i < _stepArr.count; i++) {
        // 创建竖屏collectionView
        JcxqModel *m = _stepArr[i];
        UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(WIDTH * i, 0, WIDTH, HEIGHT - 140)];
        // 求出Label高度
        CGFloat heightOfLabel = [HeightAdaption heightWithText:m.content Size:17 Width:WIDTH];
        scrollView.contentSize = CGSizeMake(0, HEIGHT - 200 + heightOfLabel);
        UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT - 200)];
        imgView.userInteractionEnabled = YES;
        [imgView sd_setImageWithURL:[NSURL URLWithString:m.pic]];
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, HEIGHT - 200 + 20, WIDTH, heightOfLabel)];
        label.text = m.content;
        label.numberOfLines = 0;
        [scrollView addSubview:label];
        [scrollView addSubview:imgView];
        [_scrollView addSubview:scrollView];
        [imgView release];
        [label release];
    }
}
// 数据处理
- (void)dataHandler
{
    [AFNModel GETWithURL:[NSString stringWithFormat:@"http://m.shougongke.com/index.php?&c=Course&a=CourseDetial&id=%@&vid=15", self.hand_id] completion:^(id result) {
        NSArray *arrTemp = [NSArray array];
        arrTemp = result[@"data"][@"step"];
        self.stepArr = [JcxqModel modelHandlerWithArray:arrTemp];
        self.step = self.stepArr.count;
        [self createScrollView];
    }];
}
// 返回
- (void)fanhui
{
    [self.navigationController popViewControllerAnimated:YES];
    self.navigationController.navigationBarHidden = NO;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
